import requests
import time
import jwt
ak = "ABbeMJ3TaEe3tF8QEDfTMrKPaPP3dbr3" # 填写access key
sk = "mQpRkkgELhHCMkhLfGeR8FCKyfaBeaGP" # 填写secret key
def encode_jwt_token(ak, sk):
    headers = {
        "alg": "HS256",
        "typ": "JWT"
    }
    payload = {
        "iss": ak,
        "exp": int(time.time()) + 1800, # 有效时间，此处示例代表当前时间+1800s(30min)
        "nbf": int(time.time()) - 5 # 开始生效的时间，此处示例代表当前时间-5秒
    }
    token = jwt.encode(payload, sk, headers=headers)
    return token
api_token = encode_jwt_token(ak, sk)

id='784856380959780887'
url=f'https://api-beijing.klingai.com//v1/images/generations/{id}'
headers = {'Content-Type': 'application/json',
           'Authorization': f'Bearer {api_token}',
           }
res=requests.get(url,headers=headers)
print(res.text)
print(res.json()['data']['task_result']['images'][0]['url'])